#include "CPoint.h"

#include <iostream>
#include <cmath>
#include <QDebug>
/**
 * @brief  Construct a new CPoint2D::CPoint2D object
 * @author Jimmy 
 * @date   2023.03.04
 */
CPoint2D::CPoint2D()
{

}

/**
 * @brief  Construct a new CPoint2D::CPoint2D object
 * @param  x                
 * @param  y                
 * @author Jimmy 
 * @date   2023.03.04
 */
CPoint2D::CPoint2D(int x, int y) :
                    m_x(x), m_y(y)
{
}

/**
 * @brief  Construct a new CPoint2D::CPoint2D object
 * @param  pt_              
 * @author Jimmy 
 * @date   2023.03.04
 */
CPoint2D::CPoint2D(const CPoint2D &pt)
{
    m_x = pt.m_x;
    m_y = pt.m_y;
}

/**
 * @brief  Destroy the CPoint2D::CPoint2D object
 * @author Jimmy 
 * @date   2023.03.04
 */
CPoint2D::~CPoint2D()
{

}

/**
 * @brief  获取值
 * @param  index            
 * @return int 
 * @author Jimmy 
 * @date   2023.03.04
 */
int CPoint2D::get(int index) const
{
    if (index == 0)
    {
        return getX();
    }
    else if (index == 1)
    {
        return getY();
    }

    return 0;
}

/**
 * @brief  获取两点间的离散点
 * @param  resolution       
 * @param  pt1              
 * @param  pt2              
 * @return std::deque<CPoint2D> 
 * @author Jimmy 
 * @date   2023.03.04
 */
std::deque<CPoint2D> CPoint2D::getPointBetweenPoints(int resolution, const CPoint2D &start_point, const CPoint2D &end_point)
{
    std::deque<CPoint2D> deque;
    deque.push_back(start_point);

    double distance = start_point.getEuclideanDistance(end_point);

    for ( int i = resolution; i < distance; i += resolution )
    {
        int x = ((distance - i) * start_point.getX() + i * end_point.getX()) / distance;
        int y = ((distance - i) * start_point.getY() + i * end_point.getY()) / distance;

        deque.push_back(CPoint2D(x, y));
    }

    if (deque.back() == end_point)
    {
        deque.push_back(end_point);
    }

    return deque;
}

/**
 * @brief  计算欧几里德距离
 * @param  pt               
 * @return double 
 * @author Jimmy 
 * @date   2023.03.04
 */
double CPoint2D::getEuclideanDistance(const CPoint2D &point) const
{
    double delta_x = m_x - point.getX();
    double delta_y = m_y - point.getY();

    return std::sqrt(delta_x * delta_x + delta_y * delta_y);
}

/**
 * @brief  计算平方的距离
 * @param  point            
 * @return int 
 * @author Jimmy 
 * @date   2023.03.04
 */
int CPoint2D::getSquareDistance(const CPoint2D &point) const
{
    double delta_x = m_x - point.getX();
    double delta_y = m_y - point.getY();

    return (delta_x * delta_x + delta_y * delta_y);
}
